#ifndef MINI_BASIC_IMPL_H
#define MINI_BASIC_IMPL_H

#pragma once

#include "stdafx.h"
#include "MiniBasic_h.h"

class MiniBasicImpl : public IMiniBasic
{
    volatile ULONG refCount;
    ITypeInfo* pTypeInf;

    static unsigned WINAPI DoFileExecutionFunc(LPVOID pParams);

    struct NewThreadParams
    {
        HANDLE hEvent;
        ExecutionParameters* pExParams;
        HRESULT hr;
    };
    STDMETHODIMP ExecuteFileImpl(ExecutionParameters* pParams, UINT_PTR* pHandle = 0);

public:
    MiniBasicImpl();
    ~MiniBasicImpl();

    // IUnknown
    STDMETHODIMP QueryInterface(REFIID iid, LPVOID* ppv);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    // IDispatch
    STDMETHODIMP GetTypeInfoCount(UINT* pInfo);
    STDMETHODIMP GetTypeInfo(UINT info, LCID lcid, LPTYPEINFO* ppInf);
    STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* ppNames, UINT namesCount, LCID lcid, DISPID* rgDispId);
    STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);

    // IMiniBasic
    STDMETHODIMP ExecuteFile(ExecutionParameters* pExParams);
    STDMETHODIMP ExecuteFileAsync(ExecutionParameters* pExParams, UINT_PTR* pHandle);
    STDMETHODIMP ExecuteString(ExecutionParameters* pExParams, SAFEARRAY* pArray, VARIANT_BOOL hasTextLineNumbers);

    static std::wstring GetFullTypeLibPath();
};

#endif
